# -*- coding: UTF-8 -*-
import pandas as pd
from pyecharts.charts import Geo
from pyecharts import options as opts
from pyecharts.globals import GeoType, CurrentConfig, ThemeType


locaddr = pd.read_csv('shanghai4月21日addresslocationclustered.csv')
print(locaddr['addr'][0:5])

centers = [[121.39972794, 31.11276039],
 [121.47230505, 31.22946159],
 [121.54074312, 31.27829433],
 [121.55194351, 31.14521658],
 [121.30595098, 31.27454957],
 [121.7883235 , 31.01742898],
 [121.19331447, 31.08723892],
 [121.43906952, 31.3528786 ],
 [121.35963692, 31.79305054],
 [121.68785925, 31.23914705]]

# 获取 地点  经纬度信息
geo_sight_coord = {locaddr.iloc[i]['addr']: [locaddr.iloc[i]['lng'], locaddr.iloc[i]['lat']] for i in range(len(locaddr))}
data = [(locaddr['addr'][j], int(locaddr['labels'][j])) for j in range(len(locaddr))]
# print(data)
# print(geo_sight_coord)

# 实例化Geo对象  导入上海地图
g = Geo(init_opts=opts.InitOpts(theme=ThemeType.PURPLE_PASSION, width="1000px", height="600px"))
g.add_schema(maptype="上海")

for k, v in list(geo_sight_coord.items()):
    # 添加地址、经纬度数据
    g.add_coordinate(k, v[0], v[1])

# 生成涟漪散点图
# g.add("", data_pair=data, type_=GeoType.EFFECT, symbol_size=6)
g.add("", data_pair=data, type_= GeoType.EFFECT_SCATTER, symbol_size=5)
g.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
pieces = [{'min': -0.5, 'max':0.5,'label': '分区0', 'color': '#006400'},
        {'min': 0.5, 'max':1.5,'label': '分区1', 'color': '#DC143C'},
        {'min': 1.5, 'max':2.5,'label': '分区2', 'color': '#FFFF00'},
        {'min': 2.5, 'max':3.5,'label': '分区3', 'color': '#FF1493'},
        {'min': 3.5, 'max':4.5,'label': '分区4', 'color': '#4B0082'},
        {'min': 4.5, 'max':5.5,'label': '分区5', 'color': '#0000FF'},
        {'min': 5.5, 'max':6.5,'label': '分区6', 'color': '#00FF7F'},
        {'min': 6.5, 'max':7.5,'label': '分区7', 'color': '#778899'},
        {'min': 7.5, 'max':8.5,'label': '分区8', 'color': '#00BFFF'},
        {'min': 8.5, 'max':9.5,'label': '分区9', 'color': '#2F4F4F	'}
         ]
g.set_global_opts(title_opts=opts.TitleOpts(title="4月21日上海新冠感染者分布图"),visualmap_opts=opts.VisualMapOpts(is_piecewise=False, pieces=pieces))
g.render("4月21日上海新冠感染者分布图.html")
